import os
import sys
from pathlib import Path
import subprocess

def install_browser():
    """安装必要的浏览器"""
    try:
        subprocess.run(['playwright', 'install', 'chromium'], check=True)
    except Exception as e:
        print(f"安装浏览器失败: {e}")
        sys.exit(1)

def main():
    # 确保目录存在
    Path("logs").mkdir(exist_ok=True)
    Path("screen_shot").mkdir(exist_ok=True)
    
    # 检查并安装浏览器
    install_browser()
    
    # 启动GUI程序
    from main import DetectionGUI
    gui = DetectionGUI()
    gui.run()

if __name__ == "__main__":
    main() 